﻿/**  版本信息模板在安装目录下，可自行修改。
* BDDICT.cs
*
* 功 能： N/A
* 类 名： BDDICT
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2013/8/8 20:06:47   N/A    初版
*
* Copyright (c) 2012 DQYT.HTDZ Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DQYT.HTDZ.IDAL;
using Maticsoft.DBUtility;
using DQYT.HTDZ.Model;
namespace DQYT.HTDZ.OracleDAL
{
	/// <summary>
	/// 数据访问类:BDDICT
	/// </summary>
	public partial class BDDICTDAL:IBDDICT
	{
		public BDDICTDAL()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(decimal TABLE_ID,string FIELD_CODE)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from BDDICT");
			strSql.Append(" where TABLE_ID=:TABLE_ID and FIELD_CODE=:FIELD_CODE ");
			OracleParameter[] parameters = {
					new OracleParameter(":TABLE_ID", OracleType.Number,22),
					new OracleParameter(":FIELD_CODE", OracleType.VarChar,30)			};
			parameters[0].Value = TABLE_ID;
			parameters[1].Value = FIELD_CODE;

			return DbHelperOra.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(DQYT.HTDZ.Model.BDDICTModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into BDDICT(");
			strSql.Append("TABLE_ID,FIELD_CODE,FIELD_NAME,FIELD_TYPE,FIELD_NULL,FIELD_LONG,FIELD_KEY,FIELD_SHOWWIDTH,FIELD_SHOW,FIELD_POPWIN,FIELD_DATASOURCE,FIELD_AUTOCOL,FIELD_UNIQUE,FIELD_ID,TABLE_CODE)");
			strSql.Append(" values (");
			strSql.Append(":TABLE_ID,:FIELD_CODE,:FIELD_NAME,:FIELD_TYPE,:FIELD_NULL,:FIELD_LONG,:FIELD_KEY,:FIELD_SHOWWIDTH,:FIELD_SHOW,:FIELD_POPWIN,:FIELD_DATASOURCE,:FIELD_AUTOCOL,:FIELD_UNIQUE,:FIELD_ID,:TABLE_CODE)");
			OracleParameter[] parameters = {
					new OracleParameter(":TABLE_ID", OracleType.Number,18),
					new OracleParameter(":FIELD_CODE", OracleType.VarChar,30),
					new OracleParameter(":FIELD_NAME", OracleType.VarChar,30),
					new OracleParameter(":FIELD_TYPE", OracleType.VarChar,4),
					new OracleParameter(":FIELD_NULL", OracleType.VarChar,30),
					new OracleParameter(":FIELD_LONG", OracleType.Number,8),
					new OracleParameter(":FIELD_KEY", OracleType.VarChar,4),
					new OracleParameter(":FIELD_SHOWWIDTH", OracleType.Number,8),
					new OracleParameter(":FIELD_SHOW", OracleType.VarChar,4),
					new OracleParameter(":FIELD_POPWIN", OracleType.VarChar,30),
					new OracleParameter(":FIELD_DATASOURCE", OracleType.VarChar,300),
					new OracleParameter(":FIELD_AUTOCOL", OracleType.VarChar,4),
					new OracleParameter(":FIELD_UNIQUE", OracleType.VarChar,4),
					new OracleParameter(":FIELD_ID", OracleType.VarChar,4),
					new OracleParameter(":TABLE_CODE", OracleType.VarChar,30)};
			parameters[0].Value = model.TABLE_ID;
			parameters[1].Value = model.FIELD_CODE;
			parameters[2].Value = model.FIELD_NAME;
			parameters[3].Value = model.FIELD_TYPE;
			parameters[4].Value = model.FIELD_NULL;
			parameters[5].Value = model.FIELD_LONG;
			parameters[6].Value = model.FIELD_KEY;
			parameters[7].Value = model.FIELD_SHOWWIDTH;
			parameters[8].Value = model.FIELD_SHOW;
			parameters[9].Value = model.FIELD_POPWIN;
			parameters[10].Value = model.FIELD_DATASOURCE;
			parameters[11].Value = model.FIELD_AUTOCOL;
			parameters[12].Value = model.FIELD_UNIQUE;
			parameters[13].Value = model.FIELD_ID;
			parameters[14].Value = model.TABLE_CODE;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(DQYT.HTDZ.Model.BDDICTModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update BDDICT set ");
			strSql.Append("FIELD_NAME=:FIELD_NAME,");
			strSql.Append("FIELD_TYPE=:FIELD_TYPE,");
			strSql.Append("FIELD_NULL=:FIELD_NULL,");
			strSql.Append("FIELD_LONG=:FIELD_LONG,");
			strSql.Append("FIELD_KEY=:FIELD_KEY,");
			strSql.Append("FIELD_SHOWWIDTH=:FIELD_SHOWWIDTH,");
			strSql.Append("FIELD_SHOW=:FIELD_SHOW,");
			strSql.Append("FIELD_POPWIN=:FIELD_POPWIN,");
			strSql.Append("FIELD_DATASOURCE=:FIELD_DATASOURCE,");
			strSql.Append("FIELD_AUTOCOL=:FIELD_AUTOCOL,");
			strSql.Append("FIELD_UNIQUE=:FIELD_UNIQUE,");
			strSql.Append("FIELD_ID=:FIELD_ID,");
			strSql.Append("TABLE_CODE=:TABLE_CODE");
			strSql.Append(" where TABLE_ID=:TABLE_ID and FIELD_CODE=:FIELD_CODE ");
			OracleParameter[] parameters = {
					new OracleParameter(":FIELD_NAME", OracleType.VarChar,30),
					new OracleParameter(":FIELD_TYPE", OracleType.VarChar,4),
					new OracleParameter(":FIELD_NULL", OracleType.VarChar,30),
					new OracleParameter(":FIELD_LONG", OracleType.Number,8),
					new OracleParameter(":FIELD_KEY", OracleType.VarChar,4),
					new OracleParameter(":FIELD_SHOWWIDTH", OracleType.Number,8),
					new OracleParameter(":FIELD_SHOW", OracleType.VarChar,4),
					new OracleParameter(":FIELD_POPWIN", OracleType.VarChar,30),
					new OracleParameter(":FIELD_DATASOURCE", OracleType.VarChar,300),
					new OracleParameter(":FIELD_AUTOCOL", OracleType.VarChar,4),
					new OracleParameter(":FIELD_UNIQUE", OracleType.VarChar,4),
					new OracleParameter(":FIELD_ID", OracleType.VarChar,4),
					new OracleParameter(":TABLE_CODE", OracleType.VarChar,30),
					new OracleParameter(":TABLE_ID", OracleType.Number,18),
					new OracleParameter(":FIELD_CODE", OracleType.VarChar,30)};
			parameters[0].Value = model.FIELD_NAME;
			parameters[1].Value = model.FIELD_TYPE;
			parameters[2].Value = model.FIELD_NULL;
			parameters[3].Value = model.FIELD_LONG;
			parameters[4].Value = model.FIELD_KEY;
			parameters[5].Value = model.FIELD_SHOWWIDTH;
			parameters[6].Value = model.FIELD_SHOW;
			parameters[7].Value = model.FIELD_POPWIN;
			parameters[8].Value = model.FIELD_DATASOURCE;
			parameters[9].Value = model.FIELD_AUTOCOL;
			parameters[10].Value = model.FIELD_UNIQUE;
			parameters[11].Value = model.FIELD_ID;
			parameters[12].Value = model.TABLE_CODE;
			parameters[13].Value = model.TABLE_ID;
			parameters[14].Value = model.FIELD_CODE;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(decimal TABLE_ID,string FIELD_CODE)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from BDDICT ");
			strSql.Append(" where TABLE_ID=:TABLE_ID and FIELD_CODE=:FIELD_CODE ");
			OracleParameter[] parameters = {
					new OracleParameter(":TABLE_ID", OracleType.Number,22),
					new OracleParameter(":FIELD_CODE", OracleType.VarChar,30)			};
			parameters[0].Value = TABLE_ID;
			parameters[1].Value = FIELD_CODE;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public DQYT.HTDZ.Model.BDDICTModel GetModel(decimal TABLE_ID,string FIELD_CODE)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select TABLE_ID,FIELD_CODE,FIELD_NAME,FIELD_TYPE,FIELD_NULL,FIELD_LONG,FIELD_KEY,FIELD_SHOWWIDTH,FIELD_SHOW,FIELD_POPWIN,FIELD_DATASOURCE,FIELD_AUTOCOL,FIELD_UNIQUE,FIELD_ID,TABLE_CODE from BDDICT ");
			strSql.Append(" where TABLE_ID=:TABLE_ID and FIELD_CODE=:FIELD_CODE ");
			OracleParameter[] parameters = {
					new OracleParameter(":TABLE_ID", OracleType.Number,22),
					new OracleParameter(":FIELD_CODE", OracleType.VarChar,30)			};
			parameters[0].Value = TABLE_ID;
			parameters[1].Value = FIELD_CODE;

			DQYT.HTDZ.Model.BDDICTModel model=new DQYT.HTDZ.Model.BDDICTModel();
			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public DQYT.HTDZ.Model.BDDICTModel DataRowToModel(DataRow row)
		{
			DQYT.HTDZ.Model.BDDICTModel model=new DQYT.HTDZ.Model.BDDICTModel();
			if (row != null)
			{
				if(row["TABLE_ID"]!=null && row["TABLE_ID"].ToString()!="")
				{
					model.TABLE_ID=decimal.Parse(row["TABLE_ID"].ToString());
				}
				if(row["FIELD_CODE"]!=null)
				{
					model.FIELD_CODE=row["FIELD_CODE"].ToString();
				}
				if(row["FIELD_NAME"]!=null)
				{
					model.FIELD_NAME=row["FIELD_NAME"].ToString();
				}
				if(row["FIELD_TYPE"]!=null)
				{
					model.FIELD_TYPE=row["FIELD_TYPE"].ToString();
				}
				if(row["FIELD_NULL"]!=null)
				{
					model.FIELD_NULL=row["FIELD_NULL"].ToString();
				}
				if(row["FIELD_LONG"]!=null && row["FIELD_LONG"].ToString()!="")
				{
					model.FIELD_LONG=decimal.Parse(row["FIELD_LONG"].ToString());
				}
				if(row["FIELD_KEY"]!=null)
				{
					model.FIELD_KEY=row["FIELD_KEY"].ToString();
				}
				if(row["FIELD_SHOWWIDTH"]!=null && row["FIELD_SHOWWIDTH"].ToString()!="")
				{
					model.FIELD_SHOWWIDTH=decimal.Parse(row["FIELD_SHOWWIDTH"].ToString());
				}
				if(row["FIELD_SHOW"]!=null)
				{
					model.FIELD_SHOW=row["FIELD_SHOW"].ToString();
				}
				if(row["FIELD_POPWIN"]!=null)
				{
					model.FIELD_POPWIN=row["FIELD_POPWIN"].ToString();
				}
				if(row["FIELD_DATASOURCE"]!=null)
				{
					model.FIELD_DATASOURCE=row["FIELD_DATASOURCE"].ToString();
				}
				if(row["FIELD_AUTOCOL"]!=null)
				{
					model.FIELD_AUTOCOL=row["FIELD_AUTOCOL"].ToString();
				}
				if(row["FIELD_UNIQUE"]!=null)
				{
					model.FIELD_UNIQUE=row["FIELD_UNIQUE"].ToString();
				}
				if(row["FIELD_ID"]!=null)
				{
					model.FIELD_ID=row["FIELD_ID"].ToString();
				}
				if(row["TABLE_CODE"]!=null)
				{
					model.TABLE_CODE=row["TABLE_CODE"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select TABLE_ID,FIELD_CODE,FIELD_NAME,FIELD_TYPE,FIELD_NULL,FIELD_LONG,FIELD_KEY,FIELD_SHOWWIDTH,FIELD_SHOW,FIELD_POPWIN,FIELD_DATASOURCE,FIELD_AUTOCOL,FIELD_UNIQUE,FIELD_ID,TABLE_CODE ");
			strSql.Append(" FROM BDDICT ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}
       

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM BDDICT ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.FIELD_CODE desc");
			}
			strSql.Append(")AS Row, T.*  from BDDICT T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperOra.Query(strSql.ToString());
		}

        /// <summary>
        /// 获得数据列表
        /// </summary>
        /// <param name="TableCode">表代码</param>
        /// <returns></returns>
        public DataSet GetList_TableCode(string TableCode)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from BDDICT where (FIELD_SHOW='1' AND table_id= ");
            strSql.Append(" (select table_id from BDDATATABLE where table_code='" + TableCode.ToString() + "'))  order by FIELD_ID asc");

            return DbHelperOra.Query(strSql.ToString());
        }

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "BDDICT";
			parameters[1].Value = "FIELD_CODE";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

